package com.example.mainstream.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.myapp.activity.GoodsCarActivity;
import com.myapp.activity.OrderActivity;
import com.myapp.activity.R;
 
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class OrderListAdapter extends BaseAdapter {

	private List<Map<String, Object>> mData;

	private LayoutInflater mInflater;

	public static HashMap<Integer, Boolean> isSelected;

	private OrderActivity context;// ���ڽ��մ��ݹ�����Context����

	private ViewHolder holder;

	public OrderListAdapter(OrderActivity context,
			List<Map<String, Object>> mData) {

		this.context = context;

		mInflater = LayoutInflater.from(context);

		this.mData = mData;

	}

	@Override
	public int getCount() {
		System.out.print("mData.size()=" + mData.size());
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		holder = null;

		// convertViewΪnull��ʱ���ʼ��convertView��
		if (convertView == null) {

			holder = new ViewHolder();

			convertView = mInflater.inflate(R.layout.activity_order_list_item,
					null);

			holder.ordernum = (TextView) convertView
					.findViewById(R.id.orderlistitem_ordernum);

			holder.id = (TextView) convertView
					.findViewById(R.id.orderlistitem_id);

			holder.id.setVisibility(View.GONE);

			holder.sumprice = (TextView) convertView
					.findViewById(R.id.orderlistitem_sumprice);

			holder.state = (TextView) convertView
					.findViewById(R.id.orderlistitem_state);

			holder.detailBtn = (Button) convertView
					.findViewById(R.id.orderlistitem_detailbtn);

			holder.recBtn = (Button) convertView
					.findViewById(R.id.orderlistitem_recbtn);

			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();

		}

		holder.ordernum.setText(mData.get(position).get("ordernum").toString());

		holder.id.setText(mData.get(position).get("id").toString());

		holder.sumprice.setText(mData.get(position).get("sumprice").toString());

		holder.state.setText(mData.get(position).get("state").toString());

		holder.detailBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				context.ViewOrderItem(mData.get(position).get("id").toString());
			}
		});

		holder.recBtn.setVisibility(View.INVISIBLE);
		
		holder.recBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

			}
		});

		if(mData.get(position).get("id").toString().equals("�ѷ���"))
		{
			holder.recBtn.setVisibility(View.VISIBLE);
		}
		return convertView;
	}

	public final class ViewHolder {

		public TextView id;

		public TextView ordernum;

		public TextView sumprice;

		public TextView state;

		public Button detailBtn;

		public Button recBtn;

	}

}
